package com.beiing.tianshuai.tianshuai.freshnews.model;

import com.beiing.tianshuai.tianshuai.dongtai.CallBack;
import com.beiing.tianshuai.tianshuai.entity.ActiveReplyBean;
import com.beiing.tianshuai.tianshuai.entity.CodeBean;
import com.beiing.tianshuai.tianshuai.entity.DiscoveryCommentBean;
import com.beiing.tianshuai.tianshuai.entity.DiscoveryCommentListBean;
import com.beiing.tianshuai.tianshuai.entity.DiscoveryDetailsBean;
import com.beiing.tianshuai.tianshuai.entity.DiscoveryIsPraiseBean;
import com.beiing.tianshuai.tianshuai.entity.DiscoveryPraiseBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicDeleteBean;
import com.beiing.tianshuai.tianshuai.entity.FollowBean;
import com.beiing.tianshuai.tianshuai.entity.FollowResultBean;
import com.beiing.tianshuai.tianshuai.network.DataManager;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by magikliu on 2017/7/28.
 */

public class DiscoveryDetailModel implements DiscoveryDetailModelImpl {

    @Override
    public void getDiscoveryDetail(String f_id, final CallBack callBack) {
        DisposableObserver<DiscoveryDetailsBean> observer = new DisposableObserver<DiscoveryDetailsBean>() {

            @Override
            public void onNext(@NonNull DiscoveryDetailsBean discoveryDetailsBean) {
                callBack.result(discoveryDetailsBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getDiscoveryDetails(f_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void getDiscoveryCommentList(String f_id, int page, int num, int type, final CallBack callBack) {
        DisposableObserver<DiscoveryCommentListBean> observer = new DisposableObserver<DiscoveryCommentListBean>() {
            @Override
            public void onNext(@NonNull DiscoveryCommentListBean discoveryCommentListBean) {
                callBack.result(discoveryCommentListBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDiscoveryCommentList(f_id, page, num, type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void commentDiscovery(String u_id, String f_id, String review, final CallBack callBack) {
        DisposableObserver<DiscoveryCommentBean> observer = new DisposableObserver<DiscoveryCommentBean>() {
            @Override
            public void onNext(@NonNull DiscoveryCommentBean discoveryCommentBean) {
                callBack.result(discoveryCommentBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDiscoveryCommentResult(u_id, f_id, review)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void getDiscoveryIsPraise(String u_id, String f_id, final CallBack callBack) {
        DisposableObserver<DiscoveryIsPraiseBean> observer = new DisposableObserver<DiscoveryIsPraiseBean>() {
            @Override
            public void onNext(@NonNull DiscoveryIsPraiseBean discoveryIsPraiseBean) {
                callBack.result(discoveryIsPraiseBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDiscoveryIsPraiseResult(u_id, f_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
        }

    @Override
    public void praiseDiscovery(String u_id, String f_id, final CallBack callBack) {
        DisposableObserver<DiscoveryPraiseBean> observer = new DisposableObserver<DiscoveryPraiseBean>() {
            @Override
            public void onNext(@NonNull DiscoveryPraiseBean discoveryPraiseBean) {
                callBack.result(discoveryPraiseBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDiscoveryPraiseResult(u_id, f_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void praiseComment(String f_id, String u_id, String c_id, final CallBack callBack) {
        DisposableObserver<DiscoveryPraiseBean> observer = new DisposableObserver<DiscoveryPraiseBean>() {
            @Override
            public void onNext(@NonNull DiscoveryPraiseBean discoveryPraiseBean) {
                callBack.result(discoveryPraiseBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDiscoveryCommentPraiseResult(f_id, u_id, c_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void isFollowed(String fromUid, String toUid, final CallBack callBack) {
        DisposableObserver<FollowBean> observer = new DisposableObserver<FollowBean>() {
            @Override
            public void onNext(@NonNull FollowBean followBean) {
                callBack.result(followBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.isFollowed(fromUid, toUid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void setFollowed(String fromUid, String toUid, final CallBack callBack) {
        DisposableObserver<FollowResultBean> observer = new DisposableObserver<FollowResultBean>() {
            @Override
            public void onNext(@NonNull FollowResultBean followResultBean) {
                callBack.result(followResultBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getFollowResult(fromUid, toUid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void deleteComment(String id, final CallBack callBack) {
        DisposableObserver<CodeBean> observer = new DisposableObserver<CodeBean>() {
            @Override
            public void onNext(CodeBean codeBean) {
                callBack.result(codeBean);
            }

            @Override
            public void onError(Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getDiscoveryCommentDelResult(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void addReply(String fid, String cid, String form_uid, String to_uid, String content, String comment, int type, String rid, final CallBack callBack) {
        DisposableObserver<ActiveReplyBean> observer = new DisposableObserver<ActiveReplyBean>() {
            @Override
            public void onNext(ActiveReplyBean activeReplyBean) {
                callBack.result(activeReplyBean);
            }

            @Override
            public void onError(Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDiscoveryReplyResult(fid, cid, form_uid, to_uid, content, comment, type, rid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void deleteReply(String fid, String id, String uid, final CallBack callBack) {
        DisposableObserver<DynamicDeleteBean> observer = new DisposableObserver<DynamicDeleteBean>() {
            @Override
            public void onNext(DynamicDeleteBean deleteBean) {
                callBack.result(deleteBean);
            }

            @Override
            public void onError(Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDiscoveryReplyDeleteResult(fid, id, uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void praiseReply(String fid, String cid, String rid, String uid, String to_uid, final CallBack callBack) {
        DisposableObserver<DiscoveryPraiseBean> observer = new DisposableObserver<DiscoveryPraiseBean>() {
            @Override
            public void onNext(DiscoveryPraiseBean discoveryPraiseBean) {
                callBack.result(discoveryPraiseBean);
            }

            @Override
            public void onError(Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getDiscoveryReplyPraiseResult(fid, cid, rid, uid, to_uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
